<template>
    <div>
        <el-container>
            <el-header>
                <el-menu
                    class="el-menu-demo"
                    mode="horizontal"
                    background-color="#2a87af"
                    text-color="#fff"
                    default-active="1"
                    active-text-color="#ffd04b">
                    <el-menu-item index="1" @click="toPage('gameStore')">游戏商城</el-menu-item>
                    <el-menu-item index="2" @click="toPageAndParams(1,12,'orderShow')">订单中心</el-menu-item>
                    <el-submenu index="3">
                        <template slot="title">
                            {{clientele.name}}&emsp;
                            <el-avatar 
                                :src="clientele.profilePhoto"
                                style="vertical-align:middle">
                            </el-avatar>
                        </template>
                      <el-menu-item index="3-1" @click="toPage('loginPage')">注册或登录</el-menu-item> 
                      <el-menu-item index="3-2" @click="logout">登出</el-menu-item>
                      <el-menu-item index="3-3" @click="toPage('personalCenter')">个人中心</el-menu-item>
                    </el-submenu>
                </el-menu>
            </el-header>
            <el-main>
                <router-view></router-view>
            </el-main>
        </el-container>
    </div>
</template>

<script>
export default {
    name:'baseMenu',
    data(){
        return{
            clientele:{
                id:'',
                name:'未登录',
                password:'',
                gameMoney:'',
                profilePhoto:'',
            }
        }
    },
    mounted(){
        this.$bus.$on('clientele',this.refreshClienteleData)
        if(localStorage.getItem("clientele")!==null){
            this.clientele=JSON.parse(localStorage.getItem("clientele"));
        }
    },
    methods:{
        toPage(val){
            this.$router.push({
                name:val
            })
        }, 
        toPageAndParams(page,pageSize,name){
            this.$router.push({
                name,
                params:{
                    page,
                    pageSize,
                }
            })
        }, 
        logout(){
            this.clientele={
                id:'',
                name:'未登录',
                password:'',
                gameMoney:'',
                profilePhoto:'',
            };
            localStorage.removeItem('clientele');
            alert("登出成功✔")
            this.$router.replace('loginPage');
        },
        refreshClienteleData(val){
            this.clientele=val;
        } 
    }
}
</script>
<style scoped>
  .el-header{
    background-color: white;
    color: rgb(7, 36, 24);
    text-align: center;
    line-height: 65px;
  }
  
  .el-aside {
    background-color: #D3DCE6;
    color: #333;
    text-align: center;
    line-height: 200px;
  }
  
  .el-main {
    background-color: white;
    color: #333;
    text-align: center;
    line-height: 100%;
  }
</style>